05. Outer Loop - Lateral Position
Lateral Position Controller
Now that we have our altitude controller, let's handle the lateral position. Once again we will be using a PID controller on the position, so it will be the same first lines of the controller you made for the controls project:
def lateral_position_control(self, pos_cmd, pos, vel_cmd):
lateral_vel_cmd = self._kp_pos * (pos_cmd[0:2] - pos[0:2]) + vel_cmd[0:2] # compute lateral velocity command from position error
lateral_vel_cmd = np.clip(lateral_vel_cmd, -self._v_max, self._v_max) # saturate as desired
return lateral_vel_cmd
NOTE: for the Crazyflie a simple P controller is all that will be necessary, however try adding the I and D terms and see how it changes the controller!
And that's it! Now we just need to choose a starting gain and see how it works.
Once you have decided on a gain, you can run this outer loop controller using the velocity_flyer.py
script as follows:
python velocity_flyer.py --uri radio://0/80/2M
Where the uri passed in should be the uri you configured for your Crazyflie.